//
//  ViewController.m
//  fen
//
//  Created by mac on 16-4-25.
//  Copyright (c) 2016年 huangfeng. All rights reserved.
//

#import "ViewController.h"
#import "Person.h"
@interface ViewController ()<UITableViewDataSource>
{
    NSArray *data;
}

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    
    UITableView *tableview = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
    tableview.dataSource = self;
    [self.view addSubview:tableview];
    
    NSBundle *boundle = [NSBundle mainBundle];
    NSURL *cu = [boundle URLForResource:@"File" withExtension:@""];
    NSString *text = [[NSString alloc]initWithContentsOfURL:cu encoding:NSUTF8StringEncoding error:nil];
    
    NSArray *arr = [text componentsSeparatedByString:@"\n"];
    NSMutableArray *hu=[NSMutableArray new];
    for (int i =0; i<arr.count; i++) {
        NSString *item = arr[i];
        NSArray *po = [item componentsSeparatedByString:@","];
        Person *pe = [Person new];
        pe.name=po[0];
        pe.tel = po[1];
        [hu addObject:pe];
    }
    data=hu;
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return data.count;
}


- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cd = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:nil];
    Person *pi = data[indexPath.row];
    cd.textLabel.text = pi.name;
    cd.detailTextLabel.text = pi.tel;
    return cd;
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
